module FES2DT6_m
use AFES_m
use Mesh2DT6_m

type, extends(AFES) :: FES2DT6
    type(mesh2DT6), pointer :: mesh2D
contains
    procedure, pass(this) :: getInfoPerNode => getInfoPerNodeT6
    procedure, pass(this) :: getInfoPerElement => getInfoPerElementT6
    procedure, pass(this) :: getInfoPerBoundary => getInfoPerBoundaryT6
end type

contains

subroutine getInfoPerNodeT6(this, i, coord)
    implicit none
    class(FES2DT6), intent(in) :: this
    integer, intent(in) :: i
    real*8, intent(out) :: coord(:)
    
    type(mesh2DT6), pointer :: mesh2D
    mesh2D => this%mesh2D
    coord = mesh2D%nodes(i)%xy
end subroutine

subroutine getInfoPerElementT6(this, i, ele, label, coord)
    implicit none
    class(FES2DT6), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(mesh2DT6), pointer :: mesh2D
    mesh2D => this%mesh2D
    ele = mesh2D%elements(i)%idx
    label = mesh2D%elements(i)%num
    coord(:, 1) = mesh2D%nodes(ele)%xy(1)
    coord(:, 2) = mesh2D%nodes(ele)%xy(2)
end subroutine

subroutine getInfoPerBoundaryT6(this, i, ele, label, coord)
    implicit none
    class(FES2DT6), intent(in) :: this
    integer, intent(in) :: i
    integer, intent(out) :: ele(:), label
    real*8, intent(out) :: coord(:, :)
    
    type(mesh2DT6), pointer :: mesh2D
    mesh2D => this%mesh2D
    ele = mesh2D%boundarys(i)%idx
    label = mesh2D%boundarys(i)%num
    coord(:, 1) = mesh2D%nodes(ele)%xy(1)
    coord(:, 2) = mesh2D%nodes(ele)%xy(2)
end subroutine

end module